<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
<meta name="format-detection" content="telephone=no" />
<title>景区资料</title>
<meta content="" name="keywords" />
<meta content="" name="description" />
<meta content="" name="copyright" />
<meta content="" name="author" />
<meta name="robots" content="noarchive">
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/map.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript" src="js/urlTool.js"></script>
<script type="text/javascript" src="js/mescroll.min.js"></script>
<script type="text/javascript" src="js/zepto.min.js"></script>
<script type="text/javascript" src="js/zepto.weui.js"></script>
<link rel="stylesheet" href="css/weui.css"/>
<link rel="stylesheet" href="css/weuix.css"/>
<link rel="stylesheet" href="css/public.css" />
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/swiper.min.css" />
<link rel="stylesheet" href="css/mescroll.min.css">
</head>

<body class="">
    <!--头部-->
    <div class="return_top bgyellow">
        <a href="viewCenter.html">
            <span class="login_home cfff">返回景区中心</span>
        </a>
    </div>
    <!--//头部结束-->
<!--主体区域-->
<div class="bgfff cb7 pl20 pr20 pb120">
    <p class="tc fz30 pt50 cblue">车主卡执行政策</p> 
    <form action="" method="post" enctype="multipart/form-data">
        <div>
            <div class="weui-cells weui-cells_form">        
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label for="date-multiple" class="weui-label fz28">不可用日期</label></div>
                    <div class="weui-cell__bd">
                            <input class="weui-input fz30" id="date-multiple" type="text" value="">
                    </div>
                </div>
            </div>
            <div id="inline-calendar"></div>              
        </div>
        <div class="bgfff c999 pt20">
            <p class="fz28">不可用周日期</p>
            <div class="clear pt10">
                <label class="fl mr20"><input type="checkbox" name="week" value="1">周一</label>                
                <label class="fl mr20"><input type="checkbox" name="week" value="2">周二</label>                
                <label class="fl mr20"><input type="checkbox" name="week" value="3">周三</label>                
                <label class="fl mr20"><input type="checkbox" name="week" value="4">周四</label>                
                <label class="fl mr20"><input type="checkbox" name="week" value="5">周五</label>                
                <label class="fl mr20"><input type="checkbox" name="week" value="6">周六</label>
                <label class="fl mr20"><input type="checkbox" name="week" value="7">周日</label>
            </div>
        </div>

        <div class="bgfff c333 pt20">
            <p class="fz28 cblue">每日限定人数</p>
            <div class="clear divImgIn pt10"> 
                <label class="fl mr20 deactivation_unchecked deactivation_select"><input type="radio" class="hide" name="limitNum" value="0" id="nolimit"  checked="checked">不限</label>                
                <label class="fl mr20 deactivation_unchecked"><input type="radio" class="hide" name="limitNum" value="1" id="limit">限制</label>
                <input placeholder="限制入园人数" id="limitNums" keyboardtype="web-search" type="text" class="viewdata_input fz28 hide">
            </div>
        </div>

        <div class="bgfff c333 pt20">
            <p class="fz28 cblue">执行政策</p>
            <div class="clear divImgIn pt10"> 
                <label class="fl mr20 deactivation_unchecked deactivation_select"><input type="radio" class="hide" name="userPolicyType" value="0" checked="checked" id="free">免费</label>
                <label class="fl mr20 deactivation_unchecked"><input type="radio" class="hide" name="userPolicyType" value="1" id="discount">打折</label>
                <input placeholder="请输入折扣数值" value="" keyboardtype="web-search" type="search" class="viewdata_input fz28 hide" id="userPolicyNum">
            </div>           
        </div>

        <div class="bgfff c333 pt20">
            <p class="fz28 cblue">是否单独使用</p>
            <div class="clear divImgIn pt10"> 
                <label class="fl mr20 deactivation_unchecked deactivation_select"><input type="radio" class="hide" name="singleUse" value="1" checked="checked" id="yes">是</label>
                <label class="fl mr20 deactivation_unchecked"><input type="radio" class="hide" name="singleUse" value="0" id="no">不是</label>
            </div>            
            <textarea name="comment" form="usrform" placeholder="政策说明" class="tickettype_textarea c999 b p10 fz28" id="userPolicyRemark"></textarea>
        </div>

        <input type="hidden" id="policyId"/>
        <div class="car_cont">
            <button type="button" class="w100 car_cont_submit fz32 cfff" onclick="return viewdataFunction()">保存</button>
        </div>
    </form> 
</div>

<!--底部-->
<div class="footerpage"></div>
<!--//底部-->
</body>
<script>
$(".footerpage").load("footer.html",'',function() {    
    $('#myCenter').addClass("select-two").children().attr("class","myCenterclick");
});

$("#limit").click(function(){
    $("#limitNums").removeClass("hide");
})
$("#nolimit").click(function(){
    $("#limitNums").addClass("hide");
})
$("#discount").click(function(){
    $("#userPolicyNum").removeClass("hide");
})
$("#free").click(function(){
    $("#userPolicyNum").addClass("hide");
})

var nouseDay=new Array();
$(function(){
    sm.req({
        url: '/sysShopPolicy/getMsg',
        dataType:'json', 
        type:'post',
        data: {},
        done: function (res){  
            if(res.data){
                $("#userPolicyNum").html(res.data.userPolicyNum);
                $("#userPolicyRemark").html(res.data.userPolicyRemark);
                $("#policyId").val(res.data.policyId);
                // alert(res.data.policyId);
                if(res.data.limitNum == 0){
                    $("#nolimit").attr("checked",true).parent().addClass('deactivation_select');
                    $("#limit").attr("checked",false).parent().removeClass('deactivation_select');
                    $("#limitNums").addClass("hide");
                }else{
                    $("#nolimit").attr("checked",false).parent().removeClass('deactivation_select');
                    $("#limit").attr("checked",true).parent().addClass('deactivation_select');
                    $("#limitNums").val(res.data.limitNum);
                    $("#limitNums").removeClass("hide");
                }

                if(res.data.userPolicyType == 0){
                    $("#free").attr("checked",true).parent().addClass('deactivation_select');
                    $("#discount").attr("checked",false).parent().removeClass('deactivation_select');
                    $("#userPolicyNum").addClass("hide");
                }else{
                    $("#free").attr("checked",false).parent().removeClass('deactivation_select');
                    $("#discount").attr("checked",true).parent().addClass('deactivation_select');
                    $("#userPolicyNum").val(res.data.userPolicyNum);
                    $("#userPolicyNum").removeClass("hide");
                }

                if(res.data.singleUse == 0){
                    $("#yes").attr("checked",false).parent().removeClass('deactivation_select');
                    $("#no").attr("checked",true).parent().addClass('deactivation_select');
                }else{
                    $("#no").attr("checked",false).parent().removeClass('deactivation_select');
                    $("#yes").attr("checked",true).parent().addClass('deactivation_select');
                }

                $.each(res.data.nousedayList,function(i,val){
                    if(val.nouseType==1){
                        $("input[name='week'][value='"+val.nouseDay+"']").attr("checked",true);
                    }else{
                        nouseDay.push(val.nouseDay)
                    }
                })
                if(nouseDay){
                    $("#date-multiple").val(nouseDay);
                    $("#date-multiple").calendar({
                        multiple: true,
                        value:nouseDay,
                        dateFormat:'yyyy-mm-dd',
                        onChange: function (p, values, displayValues) {
                            nouseDay=values;
                        }
                    });
                }
            } 
        }
    })
    return false;
});

$(function(){
    $(".divImgIn label").click(function() {
        $(this).siblings().removeClass('deactivation_select');// 删除其他兄弟元素的样式
        $(this).addClass('deactivation_select');// 添加当前元素的样式
    });
});

function viewdataFunction(){
    var nouseWeekDay = new Array();
    $("input[name='week']:checked").each(function(i){
        nouseWeekDay[i] = $(this).val();
    });
    var userPolicyNum = $('#userPolicyNum').val();
    var userPolicyRemark = $('#userPolicyRemark').val();
    var limitNum=$('input[name="limitNum"]:checked').val();
    var userPolicyType=$('input[name="userPolicyType"]:checked').val();
    var singleUse=$('input[name="singleUse"]:checked').val();
    var policyId = $('#policyId').val();
    if(limitNum>0){
        limitNum=$("#limitNums").val();
    }
    if (limitNum == "" || limitNum == undefined || limitNum == null || limitNum.length < 1){
        layer.open({
            content:'请输入入园人数！'
            ,btn: '我知道了'
        });
        return false;
    }
    
    if(userPolicyType==1){
        if (userPolicyNum == "" || userPolicyNum == undefined || userPolicyNum == null || userPolicyNum.length < 1){
            layer.open({
                content:'请输入折扣数值！'
                ,btn: '我知道了'
            });
            return false;
        }
        if (userPolicyRemark == "" || userPolicyRemark == undefined || userPolicyRemark == null || userPolicyRemark.length < 1){
        layer.open({
            content:'请输入政策说明！'
            ,btn: '我知道了'
        });
        return false;
    }
    }else{}
    

    sm.req({
        url: '/sysShopPolicy/update',
        dataType:'json', 
        type:'post',
        data: {'id':policyId,'limitNum':limitNum,'userPolicyType':userPolicyType,'userPolicyNum':userPolicyNum,'userPolicyRemark':userPolicyRemark,'singleUse':singleUse,'nouseWeekDay[]':nouseWeekDay,'nouseDay[]':nouseDay},
        done: function (res){
            // location.href="viewCenter.html";       
            layer.open({
                content:res.message
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
            return false;          
        }
    })
    return false;
}

</script>
</html>